﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MsForgeReboot.Framework.Extensions
{
    public static class String
    {
        /// <summary>
        /// Creates the unique URL title.
        /// </summary>
        /// <param name="text">The title.</param>
        /// <returns>URL friendly title for the page or the blog post</returns>
        public static string GetUrlFriendlyText(this string text)
        {
            text = text.Trim().ToLowerInvariant();

            var replacementRules = new Dictionary<string, string> {
                { " ", "-" },
                { ".", "dot-" },
                { "@", "-at-" },
                { "/", "-" },
                { @"\", "-" },
                { "#", "-" },
                { "&", "and" },
                { "=", "-" },
                { "č", "c" },
                { "ć", "c" },
                { "š", "s" },
                { "đ", "dj" },
                { "ž", "z" }
            };

            return replacementRules.Aggregate(text, (current, rule) => current.Replace(rule.Key, rule.Value));
        }

    }
}
